//
//  SCNFinancialPlannerViewController.swift
//  ShoucainuSwift
//
//  Created by 王家旭 on 2017/5/22.
//  Copyright © 2017年 Riluee. All rights reserved.
//

import UIKit

class SCNFinancialPlannerViewController: SCNTableViewController {

    fileprivate var headView: SCNFinancialPlannerHeaderView!
    
    fileprivate var textArray: Array<Array<String>>!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = "我是理财师"
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "邀请规则", style: .plain, target: self, action: #selector(rightAction))
        
        headView = SCNFinancialPlannerHeaderView(frame: CGRect(x: 0, y: 0, width: SCNConstants.SCREENWIDTH, height: 230))
        
        headView.friendListClosures = {
            self.scnPushViewController(SCNInviteFriendsListViewController())
        }
        
        self.createTableView(.zero, style: .grouped, isRefreshNewData: false, isRefreshMoreData: false) { (table) in
            table.rowHeight = 50
            table.tableHeaderView = self.headView
            table.register(SCNFinancialPlannerCell.self, forCellReuseIdentifier: "SCNFinancialPlannerCell")
        }
        
        tableView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        tableView.isHidden = false
        
        textArray = [["方式一","方式二","方式三"],["好友注册时填写你的邀请码","分享邀请好友","二维码邀请好友"]]
    }


    func rightAction() {
        let url = String(format: "%@%@", SCNRequestAPI.H5API,"static/refactor/activity/commission/rules.html")
        self.loadWeb(at: self, url: url, title: "邀请规则")
    }
    

}

extension SCNFinancialPlannerViewController {
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 3
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "SCNFinancialPlannerCell", for: indexPath) as! SCNFinancialPlannerCell
        
        cell.titleL.text = textArray[0][indexPath.row]
        cell.contenL.text = textArray[1][indexPath.row]
        cell.accessoryType = indexPath.row == 0 ? .none:.disclosureIndicator
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 40
    }
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let sectionHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: SCNConstants.SCREENWIDTH, height: 40))
        sectionHeaderView.backgroundColor = .white
        
        let titleL = UILabel(frame: CGRect(x: 12, y: 0, width: 200, height: 40))
        titleL.text = "邀请方式"
        titleL.textColor = SCNConstants.rootBackgroundColor
        titleL.font = UIFont.systemFont(ofSize: 16.0)
        sectionHeaderView.addSubview(titleL)
        
        return sectionHeaderView
    }
}
